/*******************************************************************************
 * Simple C-K Editor
 * 
 * Copyright (C) 2009 Ingi BROWN - Centre de Gestion Scientifique - Ecole des Mines ParisTech
 * Licensed under the GNU General Public License Version 3.
 * 
 * Simple C-K Editor includes source code and libraries from the JUNG Project (Java Universal Network/Graph Framework) 
 * released under the BSD license. Copyright (c) 2003-2004,  Regents of the University of California and the JUNG Project.
 * 
 * See the License.txt file for more details.
 ******************************************************************************/

/*
 * DeleteEdgeMenuItem.java
 *
 * Created on March 21, 2007, 2:47 PM; Updated May 29, 2007
 *
 * Copyright March 21, 2007 Grotto Networking
 *
 */

package edu.ensmp.ckEditor.mousePlugin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import edu.uci.ics.jung.visualization.VisualizationViewer;

/**
 * A class to implement the deletion of an edge from within a
 * PopupVertexEdgeMenuMousePlugin.
 * 
 * @author Dr. Greg M. Bernstein
 */
public class DeleteEdgeMenuItem<E> extends JMenuItem implements
		EdgeMenuListener<E> {
	private E edge;
	private VisualizationViewer visComp;

	/** Creates a new instance of DeleteEdgeMenuItem */
	public DeleteEdgeMenuItem() {
		super("Delete Edge");
		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				visComp.getPickedEdgeState().pick(edge, false);
				visComp.getGraphLayout().getGraph().removeEdge(edge);
				visComp.repaint();
			}
		});
	}

	/**
	 * Implements the EdgeMenuListener interface to update the menu item with
	 * info on the currently chosen edge.
	 * 
	 * @param edge
	 * @param visComp
	 */
	public void setEdgeAndView(E edge, VisualizationViewer visComp) {
		this.edge = edge;
		this.visComp = visComp;
		this.setText("Delete this Edge ");
	}

}
